package vista;

import java.awt.BorderLayout;
import java.awt.event.ActionListener;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VSiniestro extends javax.swing.JFrame {
	private JPanel panVSiniestro;
	private JLabel lblTituloInfSiniestro;
	private JTextField txtCodSiniestro;
	private JLabel lblCondicionSiniestro;
	private JButton btnGuardarSiniestro;
	private JButton btnModificarSiniestro;
	private JButton btnEliminarSiniestro;
	private JButton btnCancelarSiniestro;
	private JButton btnSalirSiniestro;
	private JComboBox cmbCondicionSiniestro;
	private JTextArea txtDescripcionSiniestro;
	private JComboBox cmbMesSiniestro;
	private JButton btnFechaInspeccion;
	private JLabel lblGenerarFechaInspeccion;
	private JButton btnGenerar;
	private JLabel lblPolizaSiniestro;
	private JTextField txtPolizaSiniestro;
	private JComboBox cmbAnoSiniestro;
	private JComboBox cmbDiaSiniestro;
	private JButton btnBuscarSiniestro;
	private JLabel lblDescripcionSiniestro;
	private JLabel lblFechaSiniestro;
	private JLabel lblCodSiniestro;
	private JSeparator sptTituloInfSiniestro;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				VSiniestro inst = new VSiniestro();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public VSiniestro() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setTitle("Siniestro");
			{
				panVSiniestro = new JPanel();
				getContentPane().add(panVSiniestro, "Center");
				panVSiniestro.setLayout(null);
				panVSiniestro.setBounds(0, 0, 740, 458);
				panVSiniestro.setBackground(new java.awt.Color(14,98,181));
				{
					lblTituloInfSiniestro = new JLabel();
					panVSiniestro.add(lblTituloInfSiniestro);
					lblTituloInfSiniestro.setText("Información Siniestro");
					lblTituloInfSiniestro.setBounds(246, 5, 277, 26);
					lblTituloInfSiniestro.setFont(new java.awt.Font("Andika Basic",1,18));
				}
				{
					sptTituloInfSiniestro = new JSeparator();
					panVSiniestro.add(sptTituloInfSiniestro);
					sptTituloInfSiniestro.setBounds(82, 31, 551, 11);
				}
				{
					lblCodSiniestro = new JLabel();
					panVSiniestro.add(lblCodSiniestro);
					lblCodSiniestro.setText("Código Siniestro:");
					lblCodSiniestro.setBounds(70, 84, 118, 23);
					lblCodSiniestro.setFont(new java.awt.Font("Bitstream Charter",0,14));
				}
				{
					txtCodSiniestro = new JTextField();
					panVSiniestro.add(txtCodSiniestro);
					txtCodSiniestro.setBounds(237, 83, 112, 24);
				}
				{
					lblFechaSiniestro = new JLabel();
					panVSiniestro.add(lblFechaSiniestro);
					lblFechaSiniestro.setText("Fecha Siniestro:");
					lblFechaSiniestro.setBounds(76, 164, 141, 22);
					lblFechaSiniestro.setFont(new java.awt.Font("Bitstream Charter",0,14));
				}
				{
					lblDescripcionSiniestro = new JLabel();
					panVSiniestro.add(lblDescripcionSiniestro);
					lblDescripcionSiniestro.setText("Descripción Siniestro:");
					lblDescripcionSiniestro.setBounds(64, 221, 155, 26);
					lblDescripcionSiniestro.setFont(new java.awt.Font("Bitstream Charter",0,14));
				}
				{
					btnBuscarSiniestro = new JButton();
					panVSiniestro.add(btnBuscarSiniestro);
					btnBuscarSiniestro.setText("Buscar");
					btnBuscarSiniestro.setBounds(392, 77, 108, 35);
					btnBuscarSiniestro.setBackground(new java.awt.Color(165,42,42));
				}
				{
					txtDescripcionSiniestro = new JTextArea();
					panVSiniestro.add(txtDescripcionSiniestro);
					txtDescripcionSiniestro.setBounds(237, 200, 380, 80);
				}
				{
					lblCondicionSiniestro = new JLabel();
					panVSiniestro.add(lblCondicionSiniestro);
					lblCondicionSiniestro.setText("Condición Vehículo:");
					lblCondicionSiniestro.setBounds(64, 293, 147, 24);
					lblCondicionSiniestro.setFont(new java.awt.Font("Bitstream Charter",0,14));
				}
				{
					ComboBoxModel cmbCondVehModel = 
							new DefaultComboBoxModel(
									new String[] { "Espera", "Atendido", "Rechazado" });
					cmbCondicionSiniestro = new JComboBox();
					panVSiniestro.add(cmbCondicionSiniestro);
					cmbCondicionSiniestro.setModel(cmbCondVehModel);
					cmbCondicionSiniestro.setBounds(237, 292, 118, 24);
				}
				{
					btnSalirSiniestro = new JButton();
					panVSiniestro.add(btnSalirSiniestro);
					btnSalirSiniestro.setText("Salir");
					btnSalirSiniestro.setBackground(new java.awt.Color(173,216,230));
					btnSalirSiniestro.setBounds(620, 375, 108, 41);
				}
				{
					btnCancelarSiniestro = new JButton();
					panVSiniestro.add(btnCancelarSiniestro);
					btnCancelarSiniestro.setText("Cancelar");
					btnCancelarSiniestro.setBackground(new java.awt.Color(173,216,230));
					btnCancelarSiniestro.setBounds(469, 375, 108, 41);
				}
				{
					btnEliminarSiniestro = new JButton();
					panVSiniestro.add(btnEliminarSiniestro);
					btnEliminarSiniestro.setText("Eliminar");
					btnEliminarSiniestro.setBackground(new java.awt.Color(173,216,230));
					btnEliminarSiniestro.setBounds(319, 376, 108, 41);
				}
				{
					btnModificarSiniestro = new JButton();
					panVSiniestro.add(btnModificarSiniestro);
					btnModificarSiniestro.setText("Modificar");
					btnModificarSiniestro.setBackground(new java.awt.Color(173,216,230));
					btnModificarSiniestro.setBounds(169, 376, 108, 41);
				}
				{
					btnGuardarSiniestro = new JButton();
					panVSiniestro.add(btnGuardarSiniestro);
					btnGuardarSiniestro.setText("Guardar");
					btnGuardarSiniestro.setBackground(new java.awt.Color(173,216,230));
					btnGuardarSiniestro.setBounds(19, 376, 108, 41);
				}
				{
					ComboBoxModel cmbDiaSiniestroModel = 
							new DefaultComboBoxModel(
									new String[] { "Item One", "Item Two" });
					cmbDiaSiniestro = new JComboBox();
					panVSiniestro.add(cmbDiaSiniestro);
					cmbDiaSiniestro.setModel(cmbDiaSiniestroModel);
					cmbDiaSiniestro.setBounds(237, 163, 54, 22);
				}
				{
					ComboBoxModel cmbMesSiniestroModel = 
							new DefaultComboBoxModel(
									new String[] { "Item One", "Item Two" });
					cmbMesSiniestro = new JComboBox();
					panVSiniestro.add(cmbMesSiniestro);
					cmbMesSiniestro.setModel(cmbMesSiniestroModel);
					cmbMesSiniestro.setBounds(307, 163, 57, 22);
				}
				{
					ComboBoxModel cmbAnoSiniestroModel = 
							new DefaultComboBoxModel(
									new String[] { "Item One", "Item Two" });
					cmbAnoSiniestro = new JComboBox();
					panVSiniestro.add(cmbAnoSiniestro);
					panVSiniestro.add(getTxtPolizaSiniestro());
					panVSiniestro.add(getLblPolizaSiniestro());
					panVSiniestro.add(getBtnGenerar());
					panVSiniestro.add(getLblGenerarFechaInspeccion());
					panVSiniestro.add(getBtnFechaInspeccion());
					cmbAnoSiniestro.setModel(cmbAnoSiniestroModel);
					cmbAnoSiniestro.setBounds(370, 163, 61, 22);
				}
			}
			pack();
			this.setSize(750, 483);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

	public void agregarListener(ActionListener accion) {
		this.btnBuscarSiniestro.addActionListener(accion);
		this.btnCancelarSiniestro.addActionListener(accion);
		this.btnEliminarSiniestro.addActionListener(accion);
		this.btnModificarSiniestro.addActionListener(accion);
		this.btnGuardarSiniestro.addActionListener(accion);
		this.btnSalirSiniestro.addActionListener(accion);
		this.btnGenerar.addActionListener(accion);
		this.btnFechaInspeccion.addActionListener(accion);
		
	}

	
	public void habilitarCodigo(boolean valor){
		this.txtCodSiniestro.setEnabled(valor);
	}
	
	
	public void limpiarDatos(){
		txtDescripcionSiniestro.setText("");
		txtCodSiniestro.setText("");
		txtPolizaSiniestro.setText("");
		this.cmbAnoSiniestro.setSelectedIndex(0);
		this.cmbDiaSiniestro.setSelectedIndex(0);
		this.cmbMesSiniestro.setSelectedItem(0);
		this.cmbCondicionSiniestro.setSelectedIndex(0);
	}
	
	
	public void bloquearDatos(boolean valor){
		
		this.txtDescripcionSiniestro.setEnabled(valor);
		this.cmbAnoSiniestro.setEnabled(valor);
		this.cmbCondicionSiniestro.setEnabled(valor);
		this.cmbDiaSiniestro.setEnabled(valor);
		this.cmbMesSiniestro.setEnabled(valor);
	}
	
	public void bloquearPoliza(boolean valor){
		
		this.txtPolizaSiniestro.setEnabled(valor);
	
	}

	public void habilitarGenerar(boolean valor){
		
		this.btnGenerar.setVisible(valor);
		this.btnGenerar.setEnabled(valor);
	
	}
	

	public void habilitarBuscarSiniestro(boolean valor){
		this.btnBuscarSiniestro.setEnabled(valor);
		//this.btnBuscarSiniestro.setVisible(valor);
	}
	
	public void habilitarGuardarSiniestro(boolean valor){
		this.btnGuardarSiniestro.setVisible(valor);
		//this.btnGuardarSiniestro.setEnabled(valor);
	}

	
	public void habiliarEliminarSiniestro(boolean valor){
		this.btnEliminarSiniestro.setEnabled(valor);
		//this.btnEliminarSiniestro.setVisible(valor);

	}
	
	

	public void habilitarModificar(boolean valor) {
		this.btnModificarSiniestro.setEnabled(valor);
	//	this.btnModificarSiniestro.setVisible(valor);
	}
	
	public void mostrarMensaje(String mensaje){
		JOptionPane.showMessageDialog(this, mensaje);
	}
	
	
	public void setDatosFecha(String[] dias, String[] meses, String[] annos) {
		ComboBoxModel cmbDiasModel = new DefaultComboBoxModel(dias);
		ComboBoxModel cmbMesesModel = new DefaultComboBoxModel(meses);
		ComboBoxModel cmbAnnosModel = new DefaultComboBoxModel(annos);
		this.cmbDiaSiniestro.setModel(cmbDiasModel);
		this.cmbMesSiniestro.setModel(cmbMesesModel);
		this.cmbAnoSiniestro.setModel(cmbAnnosModel);
		
	}
	
	
	public String getFechaInspeccion(){
		String fecha = cmbDiaSiniestro.getSelectedItem().toString()+"/"+ cmbMesSiniestro.getSelectedItem().toString()+"/"+cmbAnoSiniestro.getSelectedItem().toString();
		return fecha;
	}
	
	
	public String getCondicion(){
		return  cmbCondicionSiniestro.getSelectedItem().toString();
	}
	
	
	public String getTxtCodigo(){
		return txtCodSiniestro.getText();
	}
	
	
	public String getTxtDescp(){
		return txtDescripcionSiniestro.getText();
	}
	
	public String getTxtPoliza(){
		return txtPolizaSiniestro.getText();
	}
	
	public void setTxtCodigo(String cod){
		txtCodSiniestro.setText(cod);
	}
	
	public void setDatos(String desc, String fecha, String condicion, String pol){
		txtDescripcionSiniestro.setText(desc);
		txtPolizaSiniestro.setText(pol);
		int aux1, aux2;
		
		aux1 = Integer.parseInt(fecha.substring(0, 2));
		cmbDiaSiniestro.removeAll();
		aux1--;
		cmbDiaSiniestro.setSelectedIndex(aux1);
		
		
		aux1 = Integer.parseInt(fecha.substring(3, 5));
		aux1--;
		cmbMesSiniestro.removeAll();
		cmbMesSiniestro.setSelectedIndex(aux1);
		
		aux1 = Integer.parseInt(fecha.substring(6, 10));
		aux1 -= 2012;
		cmbAnoSiniestro.removeAll();
		cmbAnoSiniestro.setSelectedIndex(aux1);
		
		if (condicion.equals("Espera")){
		
			this.cmbCondicionSiniestro.setSelectedIndex(0);
			
		} else if (condicion.equals("Atendido")){
			
			this.cmbCondicionSiniestro.setSelectedIndex(1);
			
		} else {
			
			this.cmbCondicionSiniestro.setSelectedIndex(2);
		}
		

	}
	
	
	
	public boolean datosLlenos() {
		if(this.txtCodSiniestro.getText().isEmpty() || this.txtDescripcionSiniestro.getText().isEmpty() || this.txtCodSiniestro.getText().isEmpty()){
			return true;
		}
		return false;
	}
	
	private JTextField getTxtPolizaSiniestro() {
		if(txtPolizaSiniestro == null) {
			txtPolizaSiniestro = new JTextField();
			txtPolizaSiniestro.setBounds(237, 120, 112, 22);
		}
		return txtPolizaSiniestro;
	}
	
	private JLabel getLblPolizaSiniestro() {
		if(lblPolizaSiniestro == null) {
			lblPolizaSiniestro = new JLabel();
			lblPolizaSiniestro.setText("Poliza del Siniestro:");
			lblPolizaSiniestro.setBounds(70, 123, 147, 15);
		}
		return lblPolizaSiniestro;
	}
	
	private JButton getBtnGenerar() {
		if(btnGenerar == null) {
			btnGenerar = new JButton();
			btnGenerar.setText("G");
			btnGenerar.setBounds(355, 85, 23, 22);
		}
		return btnGenerar;
	}
	
	private JLabel getLblGenerarFechaInspeccion() {
		if(lblGenerarFechaInspeccion == null) {
			lblGenerarFechaInspeccion = new JLabel();
			lblGenerarFechaInspeccion.setText("Generar Inspeccion: ");
			lblGenerarFechaInspeccion.setBounds(64, 339, 192, 15);
		}
		return lblGenerarFechaInspeccion;
	}
	
	private JButton getBtnFechaInspeccion() {
		if(btnFechaInspeccion == null) {
			btnFechaInspeccion = new JButton();
			btnFechaInspeccion.setText("G. Inspeccion");
			btnFechaInspeccion.setBounds(268, 336, 51, 22);
		}
		return btnFechaInspeccion;
	}

}
